package kaug.p2;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

public class DrawPanel extends JPanel {
	
	Color color = Color.BLACK;

	List<Point> points = new ArrayList<Point>();
	
	public DrawPanel() {
		setBackground(Color.WHITE);

		addMouseMotionListener(new MouseAdapter() {
			@Override
			public void mouseDragged(MouseEvent e) {
				points.add(e.getPoint());
				repaint();
			}
		});
	}
	
	public void drawPoint(Point p) {
		Graphics g = getGraphics();
		g.drawLine(p.x, p.y, p.x, p.y);
		g.dispose();
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(color);
		g.drawLine(0, 0, 100, 100);
		Point last = null;
		for (Point p : points) {
			if (last != null) {
				g.drawLine(p.x, p.y, last.x, last.y);
			}
			last = p;
		}
	}
	
	public Color getColor() {
		return color;
	}
	
	public void setColor(Color color) {
		this.color = color;
		repaint();
	}
}
